import { ref } from "vue";
export const usePublishGoodsForm = (ruleForm) => {
  const rules = ref({
    productTitle: [
      { required: true, message: "请输入商品标题", trigger: "blur" },
    ],
    carInfoId: [
      { required: true, message: "请选择车辆信息", trigger: "change" },
    ],
    stockAmount: [
      { required: true, message: "请输入库存数量", trigger: "blur" },
    ],
    payModeList: [
      {
        type: "array",
        required: true,
        message: "请选择付汇方式",
        trigger: "change",
      },
    ],
    startHarborId: [
      { required: true, message: "请选择启运港", trigger: "change" },
    ],
    productPrice: [
      {
        validator: (_, v, callback) => {
          if (!v) {
            callback(new Error("请输入车辆价格"));
          }
          if (!ruleForm.value.productCurrency) {
            callback(new Error("请选择币种"));
          }
          callback();
        },
        trigger: "change",
      },
    ],
    tradeModeList: [
      {
        type: "array",
        required: true,
        message: "请选择可接受成交方式",
        trigger: "change",
      },
    ],
    "prodcutPicList.thumbnailUrl": [
      { required: true, message: "请上传缩略图", trigger: "change" },
    ],
    "prodcutPicList.slideshowUrls": [
      { required: true, message: "请上传轮播图", trigger: "change" },
    ],
    payTimeNodeList: [
      { required: true, message: "请选择约定付款时间", trigger: "change" },
    ],
  });

  const getTradeModeListRules = (item) => {
    return [
      {
        validator: (_, v, callback) => {
          if (!v) {
            callback(new Error("请输入车辆价格"));
          }
          if (!item.currency) {
            callback(new Error("请选择币种"));
          }
          callback();
        },
        trigger: "change",
      },
    ];
  };
  return {
    rules,
    getTradeModeListRules,
  };
};
